package com.csf.dao;

import com.csf.entity.LoginTicket;
import org.apache.ibatis.annotations.*;

@Mapper
public interface LoginTicketMapper {

//    存用户通行证
    @Insert({
        "insert into login_ticket(user_id,ticket,status,expired)",
            "values(#{userId},#{ticket},#{status},#{expired})"
    })
//    id自增长
    @Options(keyProperty = "id",useGeneratedKeys = true)
    public int insertLoginTicket(LoginTicket loginTicket);
//查看用户通行证
@Select({
        "select id,user_id,ticket,status,expired ",
        "from login_ticket where ticket=#{ticket}"
})
     LoginTicket findLoginTicket(String ticket);
//    更改通行证状态
//    如果要加入动态SQL，则需要前后都要加scripte标签
    @Update({
        "<script>",
            "update login_ticket set status=#{status} where ticket=#{ticket} ",
            "<if test=\"ticket!=null\"> ",
            "and 1=1 ",
            "</if>",
         "</script>"
    })
     int updateStatus(String ticket,int status);
}
